<template>
    <div class="teamplate-current">
        <div class="container-fluid">
            <div class="row h-query">
                <form class="form-inline">
                    <div class="biaoti">
                        库存管理
                    </div>
                    <div class="control-group form-group" style="margin-left: 10%;">
                        <label class="control-label">选择日期</label>
                        <div class="controls input-append date " style="display:inline-block;" data-date="" >
                            <input size="16" type="text" @change="check"  class="data form-control form_date" data-date-format="yyyy-mm-dd" data-link-field="dtp_input2" data-link-format="yyyy-mm-dd">
                            <span class="add-on"><i class="icon-remove"></i></span>
                            <span class="add-on"><i class="icon-th"></i></span>
                        </div>
                        <input type="hidden" id="dtp_input2" value="" /><br/>
                    </div>
                    <div class="form-group">
                        <button type="submit" class="btn btn-default" @click="equery">查询</button>
                    </div>
                    <div class="btn-group text-right" style="text-align: right;float: right;" >
                        <button v-if=" num == 0"  class="btn btn-default" @click="btn1" > 导出表格</button>
                        <button v-if=" num == 1"   class="btn btn-default" @click="btn2"> 导出表格</button>
                        <button v-if=" num == 2"  class="btn btn-default" @click="btn3"> 导出表格</button>
                        <!-- <button v-if=" num == 0" type="submit"  class="btn btn-default" ><a style="color:#fff" :href="cfg.api +'/WRLSController/selectKCPDDY?rq='+data1+'&file='+yaopinm0+'&title='+yaopinm0"  download="a.xlsx"> 导出表格0</a></button>
                        <button v-if=" num == 1" type="submit"  class="btn btn-default" ><a style="color:#fff" :href="cfg.api +'/WRLSController/selectDQKCPDDY?&file='+yaopinm1+'&title='+yaopinm1"  download="a.xlsx"> 导出表格1</a></button>
                        <button v-if=" num == 2" type="submit"  class="btn btn-default" ><a style="color:#fff" :href="cfg.api +'/WRLSController/selectDYKCPD?&file='+yaopinm2+'&title='+yaopinm2"  download="a.xlsx"> 导出表格2</a></button> -->
                     </div>
                </form>
            </div>
            <div class="row">
                <div class="list-table">
                    <div class="list-h">
                        <div class="btn-group" v-for="(item,index) in list">
                            <button class="btn" :class="{on:index!=num}" @click="tab(index)">{{item.text}}</button>
                             <!-- <button class="btn">中药配方查询</button>
                            <button class="btn">医保销售流水</button>
                            <button class="btn">效期药师指导</button> -->
                        </div>
                        
                    </div>
                    <div class="table-wrap">
                        <div class="table-box">
                            <table class="table table-striped tc" v-if=" num == 0">
                                <tbody>
                                    <tr>
                                        <th style="text-align:left;">日期</th>
                                        <th style="text-align:left;">商品编号</th>
                                        <th style="text-align:left;">比数</th>
                                        <th style="text-align:left;">商品名称</th>
                                        <th style="text-align:left;">商品规格</th>
                                        <th style="text-align:left;">包装单位</th>
                                        <th style="text-align:left;">产地</th>
                                        <th style="text-align:right;">数量</th>
                                        <th style="text-align:right;">应收金额</th>
                                        <th style="text-align:right;">实收金额</th>
                                        <th style="text-align:right;">零售价</th>
                                        <th style="text-align:right;">库存数量</th>
                                        <th style="text-align:right;">库存金额</th>
                                        <th style="text-align:left;">架位号</th>
                                        <th style="text-align:left;">特殊标识</th>
                                        
                                    </tr>
                                    <tr v-for="items in yaopin">
                                        <td style="text-align:left;">{{items.rq}}</td>
                                        <td style="text-align:left;">{{items.spbh}}</td>
                                        <td style="text-align:left;">{{items.bishu}}</td>
                                        <td style="text-align:left;">{{items.spmch}}</td>
                                        <td style="text-align:left;">{{items.shpgg}}</td>
                                        <td style="text-align:left;">{{items.dw}}</td>
                                        <td style="text-align:left;">{{items.shpchd}}</td>
                                        <td style="text-align:right;">{{items.shl | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.ysje | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.sshje | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.lshj | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.kcshl | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.kcje | formatPrice}}</td>
                                        <td style="text-align:left;">{{items.jwh}}</td>
                                        <td style="text-align:left;">{{items.tebbs}}</td>
                                    </tr>
                                </tbody>
                            </table>
                            <table class="table table-striped tc" v-if=" num == 1">
                                <tbody>
                                    <tr>
                                        <th style="text-align:left;">架位号</th>
                                        <th style="text-align:left;">商品编号</th>
                                        <th style="text-align:left;">商品名称</th>
                                        <th style="text-align:left;">商品规格</th>
                                        <th style="text-align:left;">产地</th>
                                        <th style="text-align:left;">批号</th>
                                        <th style="text-align:left;">有效期至</th>
                                        <th style="text-align:right;">零售价</th>
                                        <th style="text-align:right;">结存数量</th>
                                    </tr>
                                    <tr v-for="items in pandian">
                                        <td style="text-align:left;">{{items.jwh}}</td>
                                        <td style="text-align:left;">{{items.spbh}}</td>
                                        <td style="text-align:left;">{{items.spmch}}</td>
                                        <td style="text-align:left;">{{items.shpgg}}</td>
                                        <td style="text-align:left;">{{items.shpchd}}</td>
                                        <td style="text-align:left;">{{items.pihao}}</td>
                                        <td style="text-align:left;">{{items.sxrq}}</td>
                                        <td style="text-align:right;">{{items.lshj | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.jcshl | formatPrice}}</td>
                                     </tr>
                                </tbody>
                            </table>
                            <table class="table table-striped tc" v-if=" num == 2">
                                <tbody>
                                    <tr>
                                        <th style="text-align:left;">架位号</th>
                                        <th style="text-align:left;">商品编号</th>
                                        <th style="text-align:left;">商品名称</th>
                                        <th style="text-align:left;">商品规格</th>
                                        <th style="text-align:left;">产地</th>
                                        <th style="text-align:left;">包装单位</th>
                                        <th style="text-align:left;">批号</th>
                                        <th style="text-align:left;">有效期至</th>
                                        <th style="text-align:right;">账面数量</th>
                                        <th style="text-align:right;">账面金额</th>
                                        <th style="text-align:right;">实盘数量</th>
                                        <th style="text-align:right;">实盘金额</th>
                                        <th style="text-align:right;">成本单价</th>
                                        <th style="text-align:right;">零售价</th>
                                    </tr>
                                    <tr v-for="items in dayinpandian">
                                        <td style="text-align:left;">{{items.jwh}}</td>
                                        <td style="text-align:left;">{{items.spbh}}</td>
                                        <td style="text-align:left;">{{items.spmch}}</td>
                                        <td style="text-align:left;">{{items.shpgg}}</td>
                                        <td style="text-align:left;">{{items.shpchd}}</td>
                                        <td style="text-align:left;">{{items.dw}}</td>
                                        <td style="text-align:left;">{{items.pihao}}</td>
                                        <td style="text-align:left;">{{items.sxrq}}</td>
                                        <td style="text-align:right;">{{items.zhmshl | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.zhmje | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.shpshl | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.shpje | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.chbdj | formatPrice}}</td>
                                        <td style="text-align:right;">{{items.lshj | formatPrice}}</td>
                                        
                                    </tr>
                                </tbody>
                                
                            </table>
                        </div>
                        <div class="pager-box clearfix pt15" v-if=" num == 0">
                            <div class="pull-left">共计
                                <span class="blue">{{count6}}</span>条信息 
                                <!-- <span class="blue">{{count6}}</span>个商品 -->
                                </div>
                                <div class="pull-right">
                                    <div id="pagenav6" class="tcdPageCode"></div>
                                    
                                </div>
                           
                        </div>
                        <div class="pager-box clearfix pt15" v-if=" num == 1">
                            <div class="pull-left">共计
                                <span class="blue">{{count1}}</span>条信息 
                                <!-- <span class="blue">{{count1}}</span>个商品 -->
                                </div>
                                <div class="pull-right">
                                    <div id="pagenav1" class="tcdPageCode"></div>
                                </div>
                           
                        </div>
                        <div class="pager-box clearfix pt15" v-if=" num == 2">
                            <div class="pull-left">共计
                                <span class="blue">{{count2}}</span>条信息 
                                <!-- <span class="blue">{{count2}}</span>个商品 -->
                                </div>
                                <div class="pull-right">
                                    <div id="pagenav2" class="tcdPageCode"></div>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
 
export default {
    components: {},
    data() {
        return {
            v: 1686,
            yaopin:[],
            list: [{
                    text: '商品明细'
                }, { 
                    text: '当前库存盘点'
                },{ 
                     text: '生成库存表打印'
                }],
                num:0,
                pandian:'',
                dayinpandian:'',
                yaopin:'',
                count1:'',
                count2:'',
                count6:'',
                yaopinm0:'',
                yaopinm1:'',
                yaopinm2:'',
                data1:'',
                fdbs:''
        }
    },
    watch: {
 
    },
    methods: {
        check(e){
             let me = this;
             var a = /^(\d{4})-(\d{2})-(\d{2})$/
             if (!a.test($('.data').val())) { 
              layer.msg("日期格式不正确!");
             return false 
            } 
        },
        tab(index) {
            let me = this
            me.num = index;
            if(me.num==1){
            let me = this;
            me.getUserPageList1 = function(curr) {
			$.ajax({
                type: 'get',
                url: me.cfg.api + '/WRLSController/selectDQKCPD',
                data: {
                    page:curr || 1,
                    rows:me.row,
                    fdbs:me.fdbs
                },
                dataType: 'json',
				success : function(data) {
                    console.log("===当前库存盘点===");
                    console.log(data);
                    me.pandian=data.data.list;
                    me.count1=data.data.count;
                    console.log(me.pandian)
                    laypage({
						cont : 'pagenav1', //容器。值支持id名、原生dom对象，jquery对象,
						pages : data.data.pagCount, //总页数
						first : '第一页',
						last : '最后一页',
						curr : curr || 1, //当前页
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								me.getUserPageList1(obj.curr);
							}
						}
					});
				}
			});
        }
        
        me.getUserPageList1();
            }
            if(me.num==2){
                let me = this;
              me.getUserPageList2 = function(curr) {
			$.ajax({
                type: 'get',
                url: me.cfg.api + '/WRLSController/selectZSDYKCPD',
                data: {
                    page:curr || 1,
                    rows:me.row,
                    fdbs:me.fdbs
                },
                dataType: 'json',
				success : function(data) {
                    console.log("===展示打印库存盘点===");
                    console.log(data);
                    me.dayinpandian=data.data.list;
                    me.count2=data.data.count;
                    console.log(me.dayinpandian)
                    laypage({
						cont : 'pagenav2', //容器。值支持id名、原生dom对象，jquery对象,
						pages : data.data.pagCount, //总页数
						first : '第一页',
						last : '最后一页',
						curr : curr || 1, //当前页
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								me.getUserPageList2(obj.curr);
							}
						}
					});
				}
			});
        }
        
        me.getUserPageList2();
            }
            },
            equery(e){
                 let me = this
    me.getUserPageList6 = function(curr) {
			$.ajax({
                type: 'get',
                url: me.cfg.api + '/WRLSController/selectKCPD',
                data: {
                    page:curr || 1,
                    rows:me.row,
                    rq:$('.data').val(),
                    fdbs:me.fdbs
                  },
                   dataType: 'json',
				success : function(data) {
                     console.log("===库存管理===");
                    console.log(data);
                    if(data.code==200){
                       me.yaopin=data.data.list;
                       me.count6=data.data.count;
                       console.log(me.yaopin);
                    }
                    laypage({
						cont : 'pagenav6', //容器。值支持id名、原生dom对象，jquery对象,
						pages : data.data.pagCount, //总页数
						first : '第一页',
						last : '最后一页',
						curr : curr || 1, //当前页
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								me.getUserPageList6(obj.curr);
							}
						}
					});
				}
			});
        }
        
        me.getUserPageList6();
            },
        btn1(e){
            let me = this;
            me.data1=$('.data').val();
            var yaopinm0="商品明细";
            var downloadToken = +new Date();
            var _self=this;
			var url =me.cfg.api +'/WRLSController/selectKCPDDY?rq='+me.data1+'&file='+yaopinm0+'&title='+yaopinm0+'&fdbs='+me.fdbs;
			var obj = {
				time: downloadToken,
                url: url,
                _self:_self,
			}
			exportExcelForm(obj);
        },
        btn2(e){
            let me = this;
            var yaopinm1="当前库存盘点";
            var downloadToken = +new Date();
           var url =me.cfg.api +'/WRLSController/selectDQKCPDDY?&file='+yaopinm1+'&title='+yaopinm1+'&fdbs='+me.fdbs;
			var obj = {
				time: downloadToken,
				url: url,
			}
			exportExcelForm(obj);
        },
        btn3(e){
            let me = this;
            var yaopinm2="生成库存打印表";
			var downloadToken = +new Date();
			var url =me.cfg.api +'/WRLSController/selectDYKCPD?&file='+yaopinm2+'&title='+yaopinm2+'&fdbs='+me.fdbs;
			var obj = {
				time: downloadToken,
				url: url,
			}
			exportExcelForm(obj);
        }
       
       
    },
    mounted() {
        let me = this;
        me.fdbs= localStorage.getItem("fdbs"); 
        console.log(me.fdbs,'分店表示');
        let user = JSON.parse(sessionStorage.getItem("user"));
        if (!user) {
                router.push({
                    path: "/login"
                })
                return;
            } 
        var time=new Date();
        let fullYear=time.getFullYear();
         let getMonth=time.getMonth()+1;
         let getDate=time.getDate();
        if(getDate.toString().length==2){
            me.getDate=getDate;
        }else{
            me.getDate='0'+getDate
        }
        me.today=fullYear+"-"+getMonth+"-"+me.getDate;
        me.yaopinm0="商品明细";
        me.yaopinm1="当前库存盘点";
        me.yaopinm2="生成库存打印表";
        $('.data').val(me.today);
        me.data1=$('.data').val();
        console.log(me.data1,'日期');
       $(".data").change(function(){
        me.data1=$('.data').val();
       });
       $('.form_date').datetimepicker({
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		minView: 2,
        forceParse: 0,
    });
     let winHeight = $(window).outerHeight();
            if(winHeight<=768){
            me.row=14
            }else if(winHeight<=800){
            me.row=16
            }else if(winHeight<=863){
            me.row=20
            }else{
            me.row=22
            }
    me.getUserPageList6 = function(curr) {
			$.ajax({
                type: 'get',
                url: me.cfg.api + '/WRLSController/selectKCPD',
                data: {
                    page:curr || 1,
                    rows:me.row,
                    rq:$('.data').val(),
                    fdbs:me.fdbs
                    
                  },
                   dataType: 'json',
				success : function(data) {
                     console.log("===库存管理===");
                    console.log(data);
                    if(data.code==200){
                       me.yaopin=data.data.list;
                       me.count6=data.data.count;
                       console.log(me.yaopin);
                    }
                    laypage({
						cont : 'pagenav6', //容器。值支持id名、原生dom对象，jquery对象,
						pages : data.data.pagCount, //总页数
						first : '第一页',
						last : '最后一页',
						curr : curr || 1, //当前页
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								me.getUserPageList6(obj.curr);
							}
						}
					});
				}
			});
        }
        
        me.getUserPageList6();
    $(document).keydown(e => {
                  let key = e.keyCode;
                  if(key==13){
                     let me = this
    me.getUserPageList6 = function(curr) {
			$.ajax({
                type: 'get',
                url: me.cfg.api + '/WRLSController/selectKCPD',
                data: {
                    page:curr || 1,
                    rows:me.row,
                    rq:$('.data').val(),
                    fdbs:me.fdbs
                  },
                   dataType: 'json',
				success : function(data) {
                     console.log("===库存管理===");
                    console.log(data);
                    if(data.code==200){
                       me.yaopin=data.data.list;
                       me.count6=data.data.count;
                       console.log(me.yaopin);
                    }
                    laypage({
						cont : 'pagenav6', //容器。值支持id名、原生dom对象，jquery对象,
						pages : data.data.pagCount, //总页数
						first : '第一页',
						last : '最后一页',
						curr : curr || 1, //当前页
						jump : function(obj, first) { //触发分页后的回调
							if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
								me.getUserPageList6(obj.curr);
							}
						}
					});
				}
			});
        }
        
        me.getUserPageList6();
           }
            })
    }

}
</script>

